package com.example.demo.controller;

import com.example.demo.entity.Car;
import com.example.demo.entity.Orders;
import com.example.demo.service.CarService;
import com.example.demo.vo.Result;
import com.example.demo.vo.ResultCode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.NonNull;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: TODO
 * @Author Mr.Tang
 */
@Tag(name = "购物车接口")
@RestController
@RequestMapping("/car")
public class CarController {

    @Resource
    private CarService carService;


    @Operation(summary = "增加一条购物车信息")
    @PostMapping("/add")
    public Result addCarInfo(@Parameter(name = "userId", description = "用户id", required = true) @NonNull Long userId,
                             @Parameter(name = "goodId", description = "商品id", required = true) @NonNull Long goodId){
        // 调用service
        Integer ret = carService.addCarInfo(userId, goodId);
        // 返回
        return Result.ok(ret);
    }


    @Operation(summary = "根据id删除一条购物车记录")
    @DeleteMapping("/deleteById")
    public Result deleteById(@Parameter(name = "id", description = "购物车记录id") @NonNull Long id) {
        // 调用service
        carService.deleteById(id);
        return Result.ok(ResultCode.SUCCESS);
    }

    @Operation(summary = "根据用户id拿到对应用户的购物车信息")
    @GetMapping("/getCarByUid")
    public Result<List<Car>> getCarByUid(@Parameter(name = "userId", description = "用户id") @NonNull Long userId) {
        // 调用service
        List<Car> carsList = carService.getCarByUid(userId);
        // 成功返回
        return Result.ok(carsList);
    }


    @Operation(summary = "根据用户id获取该用户的所有购物车信息")
    @GetMapping("/getAllCarInfoByUid")
    public Result<List<Car>> getAllCarInfoByUid(@Parameter(name = "userId", description = "用户id") @NonNull Long userId) {
        // 调用service
        List<Car> list = carService.getAllCarInfoByUid(userId);
        return null;
    }

}
